<?php


namespace app\admin\controller;


use app\BaseController;
use think\facade\Db;
use think\facade\View;

class Username extends BaseController
{
    public function admin_list(){
        $username=input('username');
        if ($username==''){
            $yonghu=Db::name('sign')->where('delete',1)->paginate(4);
            $page = $yonghu->render();
            $aa=count($yonghu);
            View::assign('count',$aa);
            View::assign('page',$page);
            View::assign('info',$yonghu);
        }else{
            $yonghu=Db::name('sign')->where('delete',1)->where('name','like','%'.$username.'%')->paginate(4);
            $page = $yonghu->render();
            $aa=count($yonghu);
            View::assign('count',$aa);
            View::assign('page',$page);
            View::assign('info',$yonghu);
        }

        return View::fetch();
    }
    //用户删除
    public function yonghu_del(){
        $id=input('id');
        $st=input('delete');
        if ($st==0){
            $aa=Db::name('sign')->where('id',$id)->update(['delete'=>1]);
            if ($aa){
                return json(['status'=>1,'info'=>'删除成功']);
            }else{
                return json(['status'=>2,'info'=>'删除失败']);
            }
        }elseif($st==1){
            $aa=Db::name('sign')->where('id',$id)->update(['delete'=>0]);
            if ($aa){
                return json(['status'=>1,'info'=>'删除成功']);
            }else{
                return json(['status'=>2,'info'=>'删除失败']);
            }
        }
    }
    public function yonghu_huifu(){//用户恢复界面
        $info=Db::name('sign')->where('delete',0)->select();
        $vv=count($info);
        View::assign('count',$vv);
        View::assign('info',$info);
        return View::fetch();
    }
    public function yonghu_huifude(){//用户恢复
        $id=input('id');
        $vv=input('delete');
        if ($vv==0){
            $aa=Db::name('sign')->where('id',$id)->update(['delete'=>1]);
            if ($aa){
                return json(['code'=>100,'msg'=>'恢复成功']);
            }else{
                return json(['code'=>250,'msg'=>'恢复失败']);
            }
        }elseif($vv==1){
            $aa=Db::name('sign')->where('id',$id)->update(['delete'=>0]);
            if ($aa){
                return json(['code'=>100,'msg'=>'恢复成功']);
            }else{
                return json(['code'=>250,'msg'=>'恢复失败']);
            }
        }
    }
    public function admin_edit(){//用户修改界面
        $id=input('id');
        $aa=Db::name('sign')->where('id',$id)->find();
        View::assign('aa',$aa);
        return View::fetch();
    }
    public function admintGai(){
        $data = input('data');
        $aa=['name'=>$data['username'],'phone'=>$data['phone'],'company'=>$data['company'],'credit'=>$data['credit']];
        $bb=Db::name('sign')->where('id',$data['id'])->update($aa);
        if ($bb){
            return json(['status'=>1,'infoss'=>'修改成功']);
        }else{
            return json(['status'=>2,'infoss'=>'修改失败']);
        }
    }
    public function admin_qi()//用户启用禁用
    {
        $id = input('id');
        $state = input('state');
        if ($state == 0) {
            $aa = Db::name('sign')->where('id', $id)->update(['statas' => 1]);
            if ($aa) {
                return json(['code'=>100,'msg'=>'成功']);
            } else {
                return json(['code'=>101,'msg'=>'失败']);
            }
        } elseif ($state == 1) {
            $aa = Db::name('sign')->where('id', $id)->update(['statas' => 0]);
            if ($aa) {
                return json(['code'=>100,'msg'=>'成功']);
            } else {
                return json(['code'=>101,'msg'=>'失败']);
            }
        }
    }
}